<?php

class ProductManager extends BaseManager implements iManager {

	public function query() {
		
		$query = "SELECT * FROM PRODUCT_TBL WHERE PRODUCT_ID = ".$this->obj->getProductId();
		
		$this->db->query($query);
		
		$this->db->execute();
		
		$result = $this->db->getResultAssoc();
		
		$product = new Product_Domain();
		
		$product-> setProductId($result["product_id"]);
		$product-> setProductName($result["product_name"]);
		$product-> setProductQty($result["current_count"]);
		$product-> setProductPrice($result["current_price"]);
		$product-> setImgDirectory($result["product_img_dir"]);
		
		$this->result = $product;		
	}
	
	public function add() {
		
	}
	
	public function delete() {
		
	}
	
	public function update() {
		$data['current_count'] = $this->obj->getProductQty();
		
		$where['product_id'] = $this->obj->getProductId();
		
		$this->db->update('PRODUCT_TBL', $data, $where);

		$this->db->execute();
	}
	
	public function getProductInfo() {
	
		$condition = $this->getCondition();
		
		$query = "SELECT * FROM PRODUCT_TBL";
		
		if (!empty($condition)) {
			$query .= $condition;
		}
	
		$this->db->query($query);
	
		$this->db->execute();
	
		$result = $this->db->getResultAssoc();
				
		$product = new Product_Domain();
	
		$product->setProductId($result["product_id"]);
		$product->setProductName($result["product_name"]);
		$product->setProductQty($result["current_count"]);
		$product->setProductPrice($result["current_price"]);
		$product->setImgDirectory($result["product_img_dir"]);
		$product->setArchive($result["archive"]);
		$product->setProductDescription($result["product_description"]);
		
		$productCategory = new ProductCategory_Domain();
		
		$productCategory->setProducts($product);
		$productCategory->setCategoryId($result['product_category_id']);		
	
		$this->result = $productCategory;
	}
	
	public function getProductCategory() {
		$results = array();
		
		$query = "SELECT * FROM `product_category_tbl` ORDER BY category_name";
		
		$this->db->query($query);
		
		$this->db->execute();
		
		while ($result = $this->db->getResultAssoc()) {
			$productCategory = new ProductCategory_Domain();
			
			$productCategory->setCategoryId($result['prod_category_id']);
			$productCategory->setCategoryName($result['category_name']);
			$productCategory->setDescription($result['category_description']);
			
			$results[] =$productCategory;
		}
		
		$this->result = $results;
	}
	
	public function updateProductInfo() {
		$productCategory = $this->obj;
		$product = $productCategory->getProduct();
		
		$data[''] = $product->getProductName();
	}
}